
import CommentAPI from '../api/comment.js';

export const Comment={
   state:{
      commentlist:[],
      comment_total_count:0,
      editCommentStatus:-1,     //插入状态 0失败  1成功  -1不改变
      commentinfo:[],
      delCommentStatus:-1,       //删除状态
   },
   mutations:{
      setCommentList(state,list){
          state.commentlist=list;
      },
      setCommentTotalCount(state,total_count){
          state.comment_total_count=total_count;
      },
      setEditCommentStatus(state,status){
          state.editCommentStatus=status;
      },
      setCommentInfo(state,info){
          state.commentinfo=info;
      },
      setDelCommentStatus(state,status){
          state.delCommentStatus=status;
      }
   },
   actions:{
      loadCommentList(context,data){
          CommentAPI.getCommentList(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setCommentList',response.data.list);
                  context.commit('setCommentTotalCount',response.data.total_count);
              }
          })
      },
      //插入Comment
      editComment(context,data){
          CommentAPI.editComment(data).then(function(response){
              context.commit('setEditCommentStatus',response.data.code);
          })
      },
      //获取详情
      loadCommentInfo(context,data){
          CommentAPI.getCommentInfo(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setCommentInfo',response.data.info);
              }
          })
      },
      //删除
      delComment(context,data){
          CommentAPI.delComment(data).then(function(response){
                context.commit('setDelCommentStatus',response.data.code);
          })
      }
   },
   getters:{
      getCommentList:state =>{
         return state.commentlist
      },
      getCommentTotalCount: state =>{
         return state.comment_total_count
      },
      getEditCommentStatus:state=>{
          return state.editCommentStatus;
      },
      getCommentInfo:state => {
          return state.commentinfo;
      },
      getDelCommentStatus:state => {
          return state.delCommentStatus;
      }
   }
}
